package com.demo.resourcecode.c6;

import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.PropertyEditorRegistry;
import org.springframework.beans.propertyeditors.CustomDateEditor;

//编写自定义的属性编辑器
public class DatePropertyEditorRegistrars implements PropertyEditorRegistrar {

	private String format = "yyyy-MM-dd";

	public DatePropertyEditorRegistrars() {
		super();
		System.out.println("init DatePropertyEditorRegistrars");
	}

	public String getFormat() {
		return format;
	}

	public void setFormat(String format) {
		this.format = format;
	}

	@Override
	public void registerCustomEditors(PropertyEditorRegistry registry) {
		registry.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat(format), true));
	}

}
